package com.cbg.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbg.base.utils.SpringContextHolder;
import com.cbg.sys.entity.Line;
import com.cbg.sys.mapper.LineMapper;
import com.cbg.sys.service.ILineService;
import com.cbg.base.core.SuperServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 排班表 服务实现类
 * </p>
 *
 * @author chenbing
 * @since 2018-12-13
 */
@Service
public class LineServiceImpl extends SuperServiceImpl<LineMapper, Line> implements ILineService {
    /**
     * 从MySQL读取今明后3天的班次
     */
    public Map<String, Map<Integer, List<Line>>> linesOf3Days(){
        return SpringContextHolder.getBean(LineMapper.class).selectList(new LambdaQueryWrapper<Line>()
                .between(Line::getDateIn, LocalDate.now(), LocalDate.now().plusDays(2)))
                .stream().collect(Collectors.groupingBy(Line::getRouteId, Collectors.groupingBy(Line::getDateSign)));
    }
}
